package com.jycrm.dao.serve.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jycrm.common.PagedListHolder;
import com.jycrm.dao.core.AbstractService;
import com.jycrm.dao.serve.ICrmServiceSendStatusDao;
import com.jycrm.domain.serve.CrmServiceProductTaVo;
import com.jycrm.service.product.vo.SearchProductSendParamVo;

public class CrmServiceSendStatusDaoImpl extends AbstractService implements
		ICrmServiceSendStatusDao {
	/*
	 * public void batchInsertCrmServiceSendStatus(Long detailId, String
	 * deleted, String analysised) { Map param = new HashMap();
	 * param.put("detailId", detailId); param.put("deleted", deleted);
	 * param.put("analysised", analysised);
	 * this.sqlMapManager.insert("batchInsertCrmServiceSendStatus", param); }
	 */

	public void batchInsertCrmSmsSendTarget(Long detailId, Long smsId) {
		Map param = new HashMap();
		param.put("detailId", detailId);
		param.put("smsId", smsId);
		this.sqlMapManager.insert("batchInsertCrmSmsSendTarget", param);
	}

	public void batchInsertCrmSmsSendTargetForTa(Long serviceProductId,
			Long smsId) {
		Map param = new HashMap();
		param.put("serviceProductId", serviceProductId);
		param.put("smsId", smsId);
		this.sqlMapManager.insert("batchInsertCrmSmsSendTargetForTa", param);

	}

	public PagedListHolder getCrmServiceSendStatusVoPagedListHolder(
			SearchProductSendParamVo v, int pageSize, int pageNo) {
		Map param = new HashMap();
		param.put("startDate", v.getStartDate());
		param.put("endDate", v.getEndDate());
		param.put("detailName", v.getDetailName());
		param.put("serviceMode", v.getServiceMode());
		param.put("serviceName", v.getServiceName());
		param.put("custName",v.getTargetName());
		String productType = "doc";
		if (v.getProductType() != null && "0".equals(v.getProductType().trim())) {
			productType = "ta";
		}
		if (v.getProductType() != null && "1".equals(v.getProductType().trim())) {
			productType = "doc";
		}

		param.put("serviceType", productType);

		int total = ((Long) this.sqlMapManager.queryForObject(
				"getCrmServiceSendStatusTotal", param)).intValue();

		PagedListHolder p = new PagedListHolder();
		p.setPageSize(pageSize);
		p.setTotal(total);
		p.setPage(pageNo);
		Long rowStart = new Long(p.getPage() * p.getPageSize() + 1);
		Long rowEnd = new Long(p.getPageSize() * (p.getPage() + 1));

		param.put("rowStart", rowStart);
		param.put("rowEnd", rowEnd);
		List rs = this.sqlMapManager.queryForList(
				"getCrmServiceSendStatusPageList", param);
		p.setPageList(rs);
		return p;
	}

	public List getUnsendCrmServiceProductTaList(String serverMode,
			int pageSize, int pageNo) {
		pageNo = pageNo - 1;
		Map param = new HashMap();
		param.put("servicemethod", serverMode);
		Long rowStart = new Long(pageSize * pageNo + 1);
		Long rowEnd = new Long(pageSize * (pageNo + 1));
		param.put("rowStart", rowStart);
		param.put("rowEnd", rowEnd);
		return this.sqlMapManager.queryForList(
				"getUnsendCrmServiceProductTaList", param);
	}

	public void updateCrmServiceProductTa(CrmServiceProductTaVo vo) {
		this.sqlMapManager.update("updateCrmServiceProductTa", vo);

	}

	public PagedListHolder findCrmServiceProductTaOrderByServiceProductId(
			Long serviceProductId, final int pageSize, final int pageNo) {
		Map param = new HashMap();
		param.put("serviceProductId", serviceProductId);

		int total = ((Long) this.sqlMapManager.queryForObject(
				"findCrmServiceProductTaOrderTotalByServiceProductId", param))
				.intValue();

		PagedListHolder p = new PagedListHolder();
		p.setPageSize(pageSize);
		p.setTotal(total);
		p.setPage(pageNo);
		Long rowStart = new Long(p.getPage() * p.getPageSize() + 1);
		Long rowEnd = new Long(p.getPageSize() * (p.getPage() + 1));

		param.put("rowStart", rowStart);
		param.put("rowEnd", rowEnd);
		List rs = this.sqlMapManager.queryForList(
				"findCrmServiceProductTaOrderByServiceProductId", param);
		p.setPageList(rs);
		return p;
	}

}
